const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:[],
    IsUpdate:1,
    OtherMobile:[],
    FenLeiArr:'请选择回收种类',
    RecType:[],
    addrtishi:'请选择所在地区',
    FenLei:-1,
    Address:'',
    selectS:false,
    animationData:{},
    Province:0,
    ProvCity:[],
    ProvName:'请选择',
    CityArr:[],
    City:0,
    CityName:'',
    AreaArr:[],
    Area:0,
    AreaName:'',
    StreetArr:[],
    Street:0,
    StreetName:'',
    tit_step:1, 
    LinkMan:'',   
  },
  LinkMan:function (e) {
    this.setData({
      LinkMan:e.detail.value
    })    
  },
  Address:function (e) {
    this.setData({
      Address:e.detail.value
    })    
  },  
  addJbxx:function () {
    var that = this;
    var FjLoginLog = wx.getStorageSync('FjLoginLog'); 
    if (this.data.LinkMan.length < 2) {
      app.tishi('请输入您的姓名');return false;
    } 
    if (this.data.Province == 0 || this.data.City == 0 || this.data.Area==0 || this.data.Street == 0) {
      app.tishi('请输入选择您的所在地区');return false;
    } 
    if (this.data.Address.length < 2) {
      app.tishi('请输入您的详细地址');return false;
    }           
    var api_input = {
      UID:FjLoginLog.UID,
      LinkMan:this.data.LinkMan,
      ComAddress:this.data.Address,
      ProvinceName:this.data.ProvName,
      CityName:this.data.CityName,
      AreaName:this.data.AreaName,
      Province:this.data.Province,
      City:this.data.City,
      Area:this.data.Area,
      Street:this.data.Street,
      Sex:1,
      Hangye:'',
      Weixin:'',
      ComEmail:'',
      ZW:'',
      QQ:'',
      ComPhone:''
    }
    app.getDaoPostN('api/FJDispose/FJ_Edit_BaseInfo',api_input,r=>{
        
        if (r.code==200) {
          app.tishi(r.data);
          setTimeout(function () {
            wx.navigateBack()
          },1000)
        }else{
          app.tishi(r.data);
        }
      })   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getFJ_Get_RecType();
    this.getFJ_Get_ProvCity();
     this.FJ_Get_BaseInfo();
  },
  FJ_Get_BaseInfo:function () {
    if (app.checkFjLogin()) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog'); 
      var api_input = {
        UID:FjLoginLog.UID,
      }
      var that = this;
      app.getDaoPost('api/FJDispose/FJ_Get_BaseInfo',api_input,r=>{
        
        if (r.code==200) {
          that.setData({
            IsUpdate:r.data.IsUpdate
          })
          // if (r.data.IsUpdate == 0) {
            var info = r.data.Info[0];
            that.getAreaStreet(info.City,3);
            that.getAreaStreet(info.Area,4);
            var cityarr = that.data.ProvCity;
            for (var i = 0; i < cityarr.length; i++) {
              if (cityarr[i].id == info.Province) {
                cityarr[i].list.splice(0, 1);
                that.setData({
                  CityArr:cityarr[i].list
                })
              }
            }
            that.setData({
              addrtishi:r.data.region,
              Address:info.Address,
              Province:info.Province,
              ProvName:info.ProvName,
              City:info.City,
              CityName:info.CityName,
              Area:info.Area,
              AreaName:info.AreaName,
              Street:info.Street,
              StreetName:info.StreetName,         
              LinkMan:info.LinkMan,         
            })            
          }
        // }
      })   
    }else{
      wx.navigateTo({ url: '../../pages/login/index' }); 
    }  
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getFJ_Get_RecType:function () {
    var that = this;
    var timestamp = Date.parse(new Date());
    var storageRecType = wx.getStorageSync('storageRecType');
    var storageRecType_tamp = wx.getStorageSync('storageRecType_tamp');
    if (storageRecType && storageRecType_tamp > timestamp ) {
      storageRecType.splice(0, 1);
      this.setData({
        RecType:storageRecType
      })
    }else{
      app.getDaoPostN('api/FJDispose/FJ_Get_RecType_New','{}',function (r) {
        
        if (r.code == 200) {
          wx.setStorageSync('storageRecType',r.data);
          wx.setStorageSync('storageRecType_tamp',timestamp+604800000);
          r.data.splice(0, 1)
          that.setData({
            RecType:r.data
          })
        }
      })      
    }
  }, 
  getFJ_Get_ProvCity:function () {
    var that = this;
    var timestamp = Date.parse(new Date());
    var storageProvCity = wx.getStorageSync('storageProvCity');
    var storageProvCity_tamp = wx.getStorageSync('storageProvCity_tamp');
    if (storageProvCity && storageProvCity_tamp > timestamp ) {
      storageProvCity.splice(0, 1);
      this.setData({
        ProvCity:storageProvCity
      })
    }else{
      app.getDaoPostN('api/FJDispose/FJ_Get_ProvCity','{}',function (r) {
        if (r.code == 200) {
          wx.setStorageSync('storageProvCity',r.data);
          wx.setStorageSync('storageProvCity_tamp',timestamp+604800000);
          r.data.splice(0, 1);
          that.setData({
            ProvCity:r.data
          })
        }
      })    
    }
  },  
  fadeIn:function(){
    this.animation.translateY(0).step()
    this.setData({
      animationData: this.animation.export()//动画实例的export方法导出动画数据传递给组件的animation属性
    })    
  },
  fadeDown:function(){
    this.animation.translateY(300).step()
    this.setData({
      animationData: this.animation.export(),  
    })
  }, 
  zhuzhimaopao:function () {
    // body...
  }, 
  setpSet:function (e) {
    this.setData({
      tit_step:e.currentTarget.dataset.step
    })
  },
  selectSereet:function (e) {
    this.setData({
      Street:e.currentTarget.dataset.id,
      StreetName:e.currentTarget.dataset.name,     
    })
    var addrtishi = this.data.ProvName+'-'+this.data.CityName+'-'+this.data.AreaName+'-'+this.data.StreetName;
    this.setData({
       addrtishi:addrtishi
    })
    this.selectH();
  },
  selectP:function (e) {
    var CityArr = this.data.ProvCity[e.currentTarget.dataset.idx].list;
    CityArr.splice(0, 1);
    if (e.currentTarget.dataset.id != this.data.Province) {
      this.setData({
        AreaArr:[],
        Area:0,
        AreaName:'',
        StreetArr:[],
        Street:0,
        StreetName:'',        
      })
    }
    this.setData({
      CityName:'请选择',
      Province:e.currentTarget.dataset.id,
      ProvName:e.currentTarget.dataset.name,
      tit_step:2,
      CityArr:CityArr
    })
  },
  selectC:function (e) {
    var that = this;
    var api_input = {
      pid:e.currentTarget.dataset.id,
      lev:3
    }
    app.getDaoPostN('api/FJDispose/FJ_Get_GetRegion',api_input,r =>{
        if (r.code == 200) {
          if (that.data.City != e.currentTarget.dataset.id) {
            that.setData({
              StreetArr:[],
              Street:0,
              StreetName:'',                 
            })          
          }
          that.setData({
            AreaArr:r.data,
            City:e.currentTarget.dataset.id,
            CityName:e.currentTarget.dataset.name,
            tit_step:3,
            AreaName:'请选择',
          })
        }
    }) 
  },
  selectA:function (e) {
    var that = this;
    var api_input = {
      pid:e.currentTarget.dataset.id,
      lev:4
    }
    app.getDaoPostN('api/FJDispose/FJ_Get_GetRegion',api_input,r =>{  
        if (r.code == 200) {
          that.setData({
            StreetArr:r.data,
            Area:e.currentTarget.dataset.id,
            AreaName:e.currentTarget.dataset.name,
            tit_step:4,
            StreetName:'请选择',
          })
        }
    }) 
  },    
  selectS:function () {
    this.setData({
      selectS:true
    })
    var that=this;
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: 'ease',
    })
    this.animation = animation 
    setTimeout(function(){
      that.fadeIn();//调用显示动画
    }) 
  },
  selectH:function () {
    var that=this; 
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: 'ease',
    })
    this.animation = animation
    that.fadeDown();//调用隐藏动画   
    setTimeout(function(){
      if (that.data.Street == 0) {
        that.setData({
          selectS:false,
          proName:'请选择',
          Province:0,
          City:0,
          CityName:'',
          Area:0,
          AreaName:'',
          Street:0,
          StreetName:'',
          tit_step:1,
          addrtishi:'请选择所在地区',           
        })          
      }else{
        that.setData({
          selectS:false,          
        })
      }
    
    },200)  
  },   
  getAreaStreet:function (id,lev) {
    var that = this;
    var api_input = {
      pid:id,
      lev:lev
    }
    app.getDaoPostN('api/FJDispose/FJ_Get_GetRegion',api_input,r =>{  
        if (r.code == 200) {
           if (lev == 3) {
            that.setData({
              AreaArr:r.data
            })
           }
           if (lev == 4) {
            that.setData({
              StreetArr:r.data
            })
           }
        }
    })
  }
}) 